<cfcomponent rest="true" restpath="/user">
	
	<!--- --->
	
	<cffunction name="login" access="remote" httpmethod="GET" restpath="/login">
		<cfargument name="email" required="true" type="string" restArgSource="query" />
		<cfargument name="password" required="true" type="string" restArgSource="query" />
		
		<cfset var local = {} />
				
		<cfset local.response = {
			status=400,
			headers={},
			content=serializeJSON({error:"No Response"})
		} />
		
		<cftry>
			<cfset local.user = $.run.it('craftivityService.getUser',arguments) />
			<cfif local.user.recordcount eq 0 or arguments.email eq "" or arguments.password eq "">
				<cfset local.response.status = 401 />
				<cfset local.response.content = "Authorization Failed. No such email/password combination" />
			<cfelse>
				<cfset local.content = {
					first_name=local.user.first_name,
					last_name=local.user.last_name,
					email=local.user.email,
					user_id=local.user.id
				} />
				<cfset local.response.status = 200 />
				<cfset local.response.content = serializeJSON(local.content) />
			</cfif>

			<cfset restSetResponse(local.response) />
			
			<cfcatch>
				<cfset application.helpers.log.add(
					name="REST_Error",
					method="login",
					args=arguments,
					cfcatch=cfcatch
				) />
				<cfset local.response.status = "500" />
				<cfset local.response.content = "The server has encountered an error processing this request." />

				<!--- <cfsavecontent variable="local.dump">
					<cfdump var="#cfcatch#">
				</cfsavecontent>
				<cfset local.response.content = local.dump /> --->

				<cfset restSetResponse(local.response) />
			</cfcatch>
		</cftry>
		
	</cffunction>
	
	<!--- --->

</cfcomponent>